package com.cmw.auntapp.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cmw.auntapp.R;
import com.cmw.auntapp.model.OrderModel;
import com.cmw.auntapp.model.SettleModel;

import java.math.BigDecimal;
import java.util.List;

/**
 * 结算记录列表数据源适配器
 *  * @Auth chengmingwei
 *  * @date 2021-04-20 22:23
 */
public class SettleListAdapter extends BaseAdapter {

    private List<SettleModel> settleList;

    private Context context;

    public SettleListAdapter(Context context, List<SettleModel> settleList) {
        this.context = context;
        this.settleList = settleList;
    }

    public void setSettleList(List<SettleModel> settleList) {
        this.settleList = settleList;
    }

    @Override
    public int getCount() {
        return (null != settleList) ? settleList.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return settleList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return settleList.get(position).getId();
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) { // 如果没有复用
            convertView = View.inflate(context, R.layout.settle_list_item, null);
        }
        SettleModel model = settleList.get(position);
        if (null == model) return convertView;
        Integer xstatus = model.getXstatus();
        TextView tvCode = convertView.findViewById(R.id.tv_code);
        TextView tvAmount = convertView.findViewById(R.id.tv_amount);
        tvCode.setText(model.getCode());
        if (null == xstatus || xstatus.intValue() == 0) { //未结算
            int textColor = R.color.colorRed;
            tvAmount.setTextColor(context.getResources().getColor(textColor));
        }
        tvAmount.setText(model.getAmount().toString());
        return convertView;
    }

}
